package com.qf.lanzhou.blog.api.controller;

import com.qf.lanzhou.blog.api.dao.Impl.login.UserDaoImpl;
import com.qf.lanzhou.blog.api.dao.UserDao;
import com.qf.lanzhou.blog.api.pojo.entity.User;
import com.qf.lanzhou.blog.api.service.UserService;
import com.qf.lanzhou.blog.api.service.impl.UserServiceImp;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import java.io.IOException;
import java.util.List;

/**
 * @author Yeach-chen
 * @ClassName ShowUserServlet
 */
@WebServlet("/showList.do")
public class ShowUserServlet extends BaseServletPost {
    private UserService userService = new UserServiceImp();
    private UserDao userDao = new UserDaoImpl();

    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        //获取到当前用户名，
        System.out.println("日志");
        HttpSession session = req.getSession();
        User user = (User) session.getAttribute("user");
        if (user == null) {
            String msg = "请先登录";
            failedResultWrite(msg,resp);
            return;
        }
        System.out.println(user);
        //把用户名作为参数传入，不显示当前用户
        List<User> list = userDao.selectAllExclusionUser(user.getUserName());
        successResultWrite(list,resp);

//        List<User> list;
//        try {
//            //获取到当前用户名，
//            //把用户名作为参数传入，不显示当前用户
//            //获取数据库中的User列表
//            list = userService.getlist();
//            successResultWrite(list, resp);
//        } catch (RuntimeException e) {
//            String message = e.getMessage();
//            failedResultWrite(message, resp);
//        }


    }
}
